package com.lyw.i04collectionProblem.mapsolution;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

/**
 * map 的多线程解决方案
 *
 * @author lyw
 * @Date 2023/7/10-上午9:37
 */
public class MapProblem {

  public static void main(String[] args) {
    // java.util.ConcurrentModificationException 并发修改问题
//    Map<String, String> map = new HashMap<>();
    Map<String, String> map = new ConcurrentHashMap<>();

    for (int i = 0; i < 30; i++) {
      String k = String.valueOf(i);
      new Thread(() -> {
        map.put(k, UUID.randomUUID().toString().substring(0, 8));
        System.out.println(map);
      }, String.valueOf(i)).start();
    }
  }
}
